using System;
using System.Collections.Generic;
using System.Text;
using FlatRedBall;
using FlatRedBall.Input;
using FlatRedBall.AI.Pathfinding;
using FlatRedBall.Graphics.Animation;
using FlatRedBall.Graphics.Particle;

using FlatRedBall.Math.Geometry;
using FlatRedBall.Math.Splines;
using BitmapFont = FlatRedBall.Graphics.BitmapFont;
using Cursor = FlatRedBall.Gui.Cursor;
using GuiManager = FlatRedBall.Gui.GuiManager;

#if FRB_XNA || SILVERLIGHT
using Keys = Microsoft.Xna.Framework.Input.Keys;
using Vector3 = Microsoft.Xna.Framework.Vector3;
using Texture2D = Microsoft.Xna.Framework.Graphics.Texture2D;


#endif
using Gnome.Engine;

namespace Gnome.Entities
{
	public partial class Item
    {
        private float CLOCK_DESPAWN_TIME = 10;
        private float BAG_DESPAWN_TIME = 5;
        private float DESPAWN_FPS = 30;
        private float BAG_DROP_COOLDOWN = 1;
        public GnomePlayer Owner;

		private void CustomInitialize()
		{
            this.mCollisionBox = new AxisAlignedRectangle();
            CountdownSprite.Visible = false;
		}

        public void SetupDespawnTimer()
        {
            switch (this.CurrentState)
            {
                case VariableState.Bag:
                    despawnTimer = BAG_DESPAWN_TIME * DESPAWN_FPS;
                    CountdownSprite.CurrentChainIndex = (int)BAG_DESPAWN_TIME;
                    pickupTimer = BAG_DROP_COOLDOWN * DESPAWN_FPS;
                    CountdownSprite.CurrentChainIndex = (int)(despawnTimer/DESPAWN_FPS)+1;
                    break;
                case VariableState.Clock:
                    despawnTimer = CLOCK_DESPAWN_TIME * DESPAWN_FPS;
                    ItemSprite.AnimationSpeed = 1/(CLOCK_DESPAWN_TIME+2);
                    break;
                default:
                    break;
            }
            CountdownSprite.ScaleX = 0.5f;
            CountdownSprite.ScaleY = 0.5f;
            CountdownSprite.RelativeY = 2;
            CountdownSprite.Visible = IsTiimerVisible;
            //CountdownSprite.Animate = false;
        }

		private void CustomActivity()
		{
            if (shouldDespawn)
            {
                despawnTimer -= DESPAWN_FPS * TimeManager.SecondDifference;
                if (despawnTimer <= 0)
                    Destroy();
                else if (IsTiimerVisible && (int)(despawnTimer / DESPAWN_FPS) != CountdownSprite.CurrentChainIndex+1)
                    CountdownSprite.CurrentChainIndex = (int)(despawnTimer/DESPAWN_FPS)+1;
            }
            if (pickupTimer > 0)
                pickupTimer -= DESPAWN_FPS * TimeManager.SecondDifference;
		}

		private void CustomDestroy()
		{
            if (Owner != null)
                Owner.canPickup = true;

		}

        private static void CustomLoadStaticContent(string contentManagerName)
        {


        }


	}
}
